package com.tangsm.spring.boot.swagger3.controller;

import com.tangsm.spring.boot.swagger3.domain.Student;
import com.tangsm.spring.boot.swagger3.service.StudentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "学生管理")
@RestController
@RequestMapping("/student")
public class StudentController {

    @Autowired
    private StudentService studentService;

    /**
     * 根据学号获取学生信息
     * @param sno 学号
     * @return Student 学生信息
     */
    @ApiOperation("根据学号获取学生信息")
    @GetMapping( value = "/queryBySno")
    public Student queryBySno(String sno) {
        return this.studentService.queryBySno(sno);
    }

    /**
     * 添加
     * @param student 学生信息
     * @return 成功数
     */
    @ApiOperation(value = "添加学生")
    @PostMapping(value = "/add")
    public Integer add(@RequestBody Student student){
        return studentService.add(student);
    }

    /**
     * 删除
     * @param sno 学号
     * @return 成功数
     */
    @ApiOperation(value = "删除学生")
    @ApiImplicitParam(name="sno", value = "学号")
    @DeleteMapping(value = "deleteBySno/{sno}")
    public Integer deleteBySno(@PathVariable String sno){
        return studentService.deleteBySno(sno);
    }

    /**
     * 更新
     * @param sno 学号
     * @param student 学生信息
     * @return 成功数
     */
    @ApiOperation(value = "更新学生")
    @ApiImplicitParam(name="sno", value = "学号")
    @PutMapping(value = "update/{sno}")
    public Integer update(@PathVariable String sno, @RequestBody Student student){
        return studentService.update(student);
    }
}
